package com.help10000.rms.ui.activitys.mine.user_info.nickname

import android.os.Bundle
import com.amir.common.utils.IMEUtil
import com.amir.common.utils.ToastUtil
import com.amir.common.weight.DuplicateClickProxy
import com.help10000.rms.R
import com.help10000.rms.config.globalData
import com.help10000.rms.mvp.presenter.UpdateUserInfoPresenter
import com.help10000.rms.mvp.view.UpdateUserInfoView
import com.help10000.rms.ui.base.BaseActivity
import kotlinx.android.synthetic.main.activity_change_nickname.*

class UpdateNickNameActivity : BaseActivity<UpdateUserInfoPresenter, UpdateUserInfoView>(),
    UpdateUserInfoView {

    override fun getlayoutId(): Int {
        return R.layout.activity_change_nickname
    }

    override fun initView() {

    }

    override fun initData(savedInstanceState: Bundle?) {
        et_nickname.setText(globalData.userInfo?.UserName)
        et_nickname.requestFocus()
        IMEUtil.showIME(this, et_nickname)
    }

    override fun initListener() {
        btn_aff.setOnClickListener(DuplicateClickProxy {
            mPresenter.updateNickname(
                et_nickname.text.toString()
            )
        })
    }

    override fun createPresenter(): UpdateUserInfoPresenter {
        return UpdateUserInfoPresenter(this)
    }

    override fun onSuccess() {
        ToastUtil.show("修改成功")
        globalData.userInfo?.UserName = et_nickname.text.toString()
        finish()
    }
}